package com.example.qcrmdemo.service.impl;

import com.example.qcrmdemo.dao.SalesChanncesMapper;
import com.example.qcrmdemo.entity.SalesChannces;
import com.example.qcrmdemo.service.SalesChanncesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SalesChanncesServiceImpl implements SalesChanncesService {

    @Autowired
    private SalesChanncesMapper salesChanncesMapper;

    @Override
    public PageInfo<SalesChannces> selectAll() {
        final List<SalesChannces> salesChannces = salesChanncesMapper.selectAll();
        PageInfo<SalesChannces> pageInfo = new PageInfo<>(salesChannces);
        return pageInfo;
    }

//    @Override
//    public PageInfo<SalesChannces> selectAll() {
//        final List<SalesChannces> salesChannces = salesChanncesMapper.selectAll();
//        PageInfo<SalesChannces> pageInfo = new PageInfo<>(salesChannces);
//        return pageInfo;
//    }

    @Override
    public PageInfo<SalesChannces> selectAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        final List<SalesChannces> salesChannces = salesChanncesMapper.selectAll();
        PageInfo<SalesChannces> pageInfo = new PageInfo<>(salesChannces);
        return pageInfo;
    }

    @Override
    public PageInfo<SalesChannces> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        final List<SalesChannces> salesChannces = salesChanncesMapper.findByKeyword(keyword);
        PageInfo<SalesChannces> pageInfo = new PageInfo<>(salesChannces);
        return pageInfo;
    }

    @Override
    public SalesChannces findById(int id) {
        return salesChanncesMapper.selectById(id);
    }

    @Override
    public boolean append(SalesChannces salesChannces) {
        return salesChanncesMapper.insert(salesChannces) > 0;
    }
}
